# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
  
  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password


  # Recibe y devuelve la direccion ip con la cual esta conectado el computador
  def obtencionip

    orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
    UDPSocket.open do |s|
      s.connect '64.233.187.99', 1
      s.addr.last
    end
  ensure
    Socket.do_not_reverse_lookup = orig
  end

  #  private
  #  def set_locale
  #    locale = params[:locale] || 'es'
  #    I18n.locale = locale
  #    I18n.load_path += Dir[ File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}') ]
  #  end

  #   def set_locale
  #      I18n.locale = params[:locale] || I18n.default_locale
  #   end
  #
  #  def default_url_options(options={})
  #    logger.debug "default_url_options is passed options: #{options.inspect}\n"
  #    { :locale => I18n.locale }
  #  end
  before_filter :set_locale

  # Metodo que permite setea a la sesion local los parametros del idioma que desee
  def set_locale

    session[:locale] = params[:locale] || 'es'
    if params[:locale]
      I18n.locale = session[:locale]
    end
  end
end
